home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODMisc / Sources / SLSUSink.cpp < prev   
Encoding:
Text File  |  1996-08-16  |  13.7 KB  |  499 lines  |  [TEXT/MPS ]

  1. //
  2. //    File:                SLSUSink.cpp
  3. //    Release Version:    $ ODF 1 $
  4. //
  5. //    Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  6. //
  7.  
  8. #include "FWOS.hpp"
  9.  
  10. #ifndef FWSTDDEF_H
  11. #include "FWStdDef.h"
  12. #endif
  13.  
  14. #ifndef FWBARRAY_H
  15. #include "FWBArray.h"
  16. #endif
  17.  
  18. #ifndef FWPRIDEB_H
  19. #include "FWPriDeb.h"
  20. #endif
  21.  
  22. #ifndef FWEXCEPT_H
  23. #include "FWExcept.h"
  24. #endif
  25.  
  26. // ----- OpenDoc Includes -----
  27.  
  28. #ifndef SOM_ODStorageUnit_xh
  29. #include <StorageU.xh>
  30. #endif
  31.  
  32. #ifndef SOM_ODStorageUnitView_xh
  33. #include <SUView.xh>
  34. #endif
  35.  
  36. // ----- Platform Includes -----
  37.  
  38. #if defined(FW_BUILD_MAC) & !defined(SOMCorba_h)
  39. #include <somcorba.h>
  40. #endif
  41.  
  42.  
  43. /*
  44.  *  This file was generated by the SOM Compiler.
  45.  *  Generated using: 
  46.  *      SOM Emitter emitxtm.dll: 2.33
  47.  */
  48.  
  49. #define FW_OStorageUnitSink_Class_Source
  50. class FW_CPrivSUSinkRep;
  51. #include "SLSUSink.xih"
  52.  
  53.  
  54. //========================================================================================
  55. //    RunTime Info
  56. //========================================================================================
  57.  
  58. #ifdef FW_BUILD_MAC
  59. #pragma segment fwodmisc
  60. #endif
  61.  
  62. //========================================================================================
  63. //    CLASS FW_CPrivSUSinkRep
  64. //========================================================================================
  65.  
  66. class FW_CPrivSUSinkRep
  67. {
  68. public:
  69.     FW_DECLARE_AUTO(FW_CPrivSUSinkRep)
  70.  
  71.     FW_CPrivSUSinkRep(Environment* ev, 
  72.                       ODStorageUnitView* storageUnitView);
  73.     FW_CPrivSUSinkRep(Environment* ev, 
  74.                       ODStorageUnit* storageUnit, 
  75.                       ODPropertyName propertyName, 
  76.                       ODValueType valueType);
  77.  
  78.     ~FW_CPrivSUSinkRep();
  79.  
  80. public:
  81.     // ----- Random Access Sink Protocol
  82.     long  GetPosition(Environment* ev);
  83.     void  SetPosition(Environment* ev, long position);
  84.     long  GetLength(Environment* ev);
  85.     void  SetLength(Environment* ev, long length);
  86.  
  87.     void  Read(Environment* ev, void* destination, long count);
  88.     
  89.     long  GetWritableBytes(Environment* ev);
  90.     void  Write(Environment* ev, void* source, long count);
  91.  
  92. public:
  93.     void  Acquire(Environment* ev);
  94.  
  95. public:
  96.     ODStorageUnitView*        fStorageUnitView;
  97.     FW_Boolean                fOwnsView;
  98. };
  99.  
  100. FW_DEFINE_AUTO(FW_CPrivSUSinkRep)
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    FW_CPrivSUSinkRep::FW_CPrivSUSinkRep
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_CPrivSUSinkRep::FW_CPrivSUSinkRep(Environment* ev, 
  107.                                      ODStorageUnitView* storageUnitView) :
  108.     fStorageUnitView(storageUnitView), 
  109.     fOwnsView(FALSE)
  110. {
  111.     Acquire(ev);
  112.  
  113.     FW_END_CONSTRUCTOR
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CPrivSUSinkRep::FW_CPrivSUSinkRep
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_CPrivSUSinkRep::FW_CPrivSUSinkRep(Environment* ev,
  121.                                      ODStorageUnit* storageUnit, 
  122.                                      ODPropertyName propertyName, 
  123.                                      ODValueType valueType) :
  124.     fStorageUnitView(0), 
  125.     fOwnsView(TRUE)
  126. {
  127.     FW_ASSERT(propertyName != NULL);
  128.     FW_ASSERT(valueType != NULL);
  129.     
  130.     storageUnit->Focus(ev, 
  131.                        propertyName, kODPosUndefined, 
  132.                        valueType, (ODValueIndex)0, kODPosUndefined);
  133.     fStorageUnitView = storageUnit->CreateView(ev);
  134.  
  135.     Acquire(ev);
  136.  
  137.     FW_END_CONSTRUCTOR
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CPrivSUSinkRep::~FW_CPrivSUSinkRep
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CPrivSUSinkRep::~FW_CPrivSUSinkRep()
  145. {
  146.     FW_START_DESTRUCTOR
  147.  
  148.     FW_SOMEnvironment ev;
  149.     
  150. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  151.     if (fStorageUnitView)
  152.         fStorageUnitView->GetStorageUnit(ev)->Release(ev);
  153. #endif
  154.  
  155.     if (fOwnsView)
  156.         delete fStorageUnitView;
  157. }
  158.  
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //     FW_CPrivSUSinkRep::GetPosition
  162. //----------------------------------------------------------------------------------------
  163.  
  164. inline long FW_CPrivSUSinkRep::GetPosition(Environment* ev)
  165. {
  166.     return fStorageUnitView->GetOffset(ev);
  167. }
  168.  
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_CPrivSUSinkRep::SetPosition
  172. //----------------------------------------------------------------------------------------
  173.  
  174. inline void FW_CPrivSUSinkRep::SetPosition(Environment* ev, long position)
  175. {
  176.     fStorageUnitView->SetOffset(ev, position);
  177. }
  178.  
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //     FW_CPrivSUSinkRep::GetLength
  182. //----------------------------------------------------------------------------------------
  183.  
  184. inline long FW_CPrivSUSinkRep::GetLength(Environment* ev)
  185. {
  186.     return fStorageUnitView->GetSize(ev);
  187. }
  188.  
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //     FW_CPrivSUSinkRep::SetLength
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void FW_CPrivSUSinkRep::SetLength(Environment* ev, long length)
  195. {
  196.     long prevLength = GetLength(ev);
  197.  
  198.     if (length < prevLength)
  199.     {
  200.         SetPosition(ev, length);
  201.         fStorageUnitView->DeleteValue(ev, prevLength-length);
  202.     }
  203.     else if (length > prevLength)
  204.     {
  205.         const long kSize = 128;
  206. #if defined(__MWERKS__) && GENERATING68K
  207.         char buffer[kSize];
  208.         FW_PrimitiveSetMemory(buffer, kSize, 0);
  209. #else
  210.         char buffer[kSize] = {0};
  211. #endif
  212.         SetPosition(ev, prevLength);
  213.         length -= prevLength;
  214.         while (length > 0)
  215.         {
  216.             long bytes = length < kSize ? length : kSize;
  217.             Write(ev, buffer, bytes);
  218.             length -= bytes;
  219.         }
  220.     }
  221. }
  222.  
  223.  
  224. //----------------------------------------------------------------------------------------
  225. //    FW_CPrivSUSinkRep::Read
  226. //----------------------------------------------------------------------------------------
  227.  
  228. inline void FW_CPrivSUSinkRep::Read(Environment* ev, void* destination, long count)
  229. {
  230. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  231.     FW_CByteArray    byteArray;
  232.  
  233.     fStorageUnitView->GetValue(ev, count, byteArray);
  234.     byteArray.CopyBuffer(destination, count);
  235. #elif FW_OPENDOC_VERSION == FW_OPENDOC_DR2
  236.     FW_CByteArray    byteArray(destination, count);
  237.  
  238.     fStorageUnitView->GetValue(ev, byteArray);
  239. #else
  240.     fStorageUnitView->GetValue(ev, count, destination);
  241. #endif
  242. }
  243.  
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    FW_CPrivSUSinkRep::GetWritableBytes
  247. //----------------------------------------------------------------------------------------
  248.  
  249. long FW_CPrivSUSinkRep::GetWritableBytes(Environment* ev)
  250. {
  251. FW_UNUSED(ev);
  252.     return 0x7FFFFFFFL;
  253. }
  254.  
  255.  
  256. //----------------------------------------------------------------------------------------
  257. //    FW_CPrivSUSinkRep::Write
  258. //----------------------------------------------------------------------------------------
  259.  
  260. void FW_CPrivSUSinkRep::Write(Environment* ev, void* source, long count)
  261. {
  262. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR2
  263.     FW_CByteArray    byteArray(source, count);
  264.     
  265.     fStorageUnitView->SetValue(ev, byteArray);
  266. #else
  267.     fStorageUnitView->SetValue(ev, count, source);
  268. #endif
  269. }
  270.  
  271.  
  272. //----------------------------------------------------------------------------------------
  273. //    FW_CPrivSUSinkRep::Acquire
  274. //----------------------------------------------------------------------------------------
  275.  
  276. void FW_CPrivSUSinkRep::Acquire(Environment* ev)
  277. {
  278. #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
  279.     if (fStorageUnitView)
  280.         fStorageUnitView->GetStorageUnit(ev)->Acquire(ev);
  281. #endif
  282. }
  283.  
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // FW_OStorageUnitSink__InitFromStorageUnitView
  287. //----------------------------------------------------------------------------------------
  288.  
  289. /*
  290.  *  Create a sink attached to the storage unit view.
  291.  *  The sink does not assume ownership of the view.
  292.  */
  293.  
  294. SOM_Scope void  SOMLINK FW_OStorageUnitSink__InitFromStorageUnitView(FW_OStorageUnitSink *somSelf, Environment *ev,
  295.         ODStorageUnitView* storageUnitView)
  296. {
  297.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  298.  
  299.     FW_SOM_TRY
  300.     {
  301.         somThis->fRep = FW_NEW(FW_CPrivSUSinkRep, (ev, storageUnitView));
  302.     }
  303.     FW_SOM_CATCH
  304. }
  305.  
  306.  
  307. //----------------------------------------------------------------------------------------
  308. // FW_OStorageUnitSink__InitFromStorageUnitAndProperty
  309. //----------------------------------------------------------------------------------------
  310.  
  311. /*
  312.  *  Create a sink attached to the given (storageUnit, propertyName, valueType).
  313.  */
  314.  
  315. SOM_Scope void  SOMLINK FW_OStorageUnitSink__InitFromStorageUnitAndProperty(FW_OStorageUnitSink *somSelf, Environment *ev,
  316.         ODStorageUnit* storageUnit,
  317.         ODPropertyName propertyName,
  318.         ODValueType valueType)
  319. {
  320.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  321.  
  322.     FW_SOM_TRY
  323.     {
  324.         somThis->fRep = FW_NEW(FW_CPrivSUSinkRep, (ev, storageUnit, propertyName, valueType));
  325.     }
  326.     FW_SOM_CATCH
  327. }
  328.  
  329.  
  330. //----------------------------------------------------------------------------------------
  331. // FW_OStorageUnitSink__GetStorageUnitView
  332. //----------------------------------------------------------------------------------------
  333.  
  334. SOM_Scope ODStorageUnitView*  SOMLINK FW_OStorageUnitSink__GetStorageUnitView(FW_OStorageUnitSink *somSelf, Environment *ev)
  335. {
  336. FW_UNUSED(ev);
  337.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  338.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  339.  
  340.     return rep.fStorageUnitView;
  341. }
  342.  
  343.  
  344. //----------------------------------------------------------------------------------------
  345. // FW_OStorageUnitSink__somInit
  346. //----------------------------------------------------------------------------------------
  347.  
  348. SOM_Scope void  SOMLINK FW_OStorageUnitSink__somInit(FW_OStorageUnitSink *somSelf)
  349. {
  350.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  351.  
  352.     FW_OStorageUnitSink_parent_FW_ORandomAccessSink_somInit(somSelf);
  353. }
  354.  
  355.  
  356. //----------------------------------------------------------------------------------------
  357. // FW_OStorageUnitSink__somUninit
  358. //----------------------------------------------------------------------------------------
  359.  
  360. SOM_Scope void  SOMLINK FW_OStorageUnitSink__somUninit(FW_OStorageUnitSink *somSelf)
  361. {
  362.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  363.  
  364.     FW_SOM_UNINIT_TRY
  365.     {
  366.         delete somThis->fRep;
  367.         FW_OStorageUnitSink_parent_FW_ORandomAccessSink_somUninit(somSelf);
  368.     }
  369.     FW_SOM_UNINIT_CATCH
  370. }
  371.  
  372.  
  373. //----------------------------------------------------------------------------------------
  374. // FW_OStorageUnitSink__Read
  375. //----------------------------------------------------------------------------------------
  376.  
  377. SOM_Scope void  SOMLINK FW_OStorageUnitSink__Read(FW_OStorageUnitSink *somSelf, Environment *ev,
  378.         void* destination,
  379.         long count)
  380. {
  381.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  382.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  383.  
  384.     FW_SOM_TRY
  385.     {
  386.         rep.Read(ev, destination, count);
  387.     }
  388.     FW_SOM_CATCH
  389. }
  390.  
  391.  
  392. //----------------------------------------------------------------------------------------
  393. // FW_OStorageUnitSink__GetWritableBytes
  394. //----------------------------------------------------------------------------------------
  395.  
  396. SOM_Scope long  SOMLINK FW_OStorageUnitSink__GetWritableBytes(FW_OStorageUnitSink *somSelf, Environment *ev)
  397. {
  398.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  399.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  400.  
  401.     FW_SOM_TRY
  402.     {
  403.         return rep.GetWritableBytes(ev);
  404.     }
  405.     FW_SOM_CATCH
  406.     return 0;
  407. }
  408.  
  409.  
  410. //----------------------------------------------------------------------------------------
  411. // FW_OStorageUnitSink__Write
  412. //----------------------------------------------------------------------------------------
  413.  
  414. SOM_Scope void  SOMLINK FW_OStorageUnitSink__Write(FW_OStorageUnitSink *somSelf, Environment *ev,
  415.         void* source,
  416.         long count)
  417. {
  418.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  419.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  420.  
  421.     FW_SOM_TRY
  422.     {
  423.         rep.Write(ev, source, count);
  424.     }
  425.     FW_SOM_CATCH
  426. }
  427.  
  428.  
  429. //----------------------------------------------------------------------------------------
  430. // FW_OStorageUnitSink__GetLength
  431. //----------------------------------------------------------------------------------------
  432.  
  433. SOM_Scope long  SOMLINK FW_OStorageUnitSink__GetLength(FW_OStorageUnitSink *somSelf, Environment *ev)
  434. {
  435.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  436.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  437.  
  438.     FW_SOM_TRY
  439.     {
  440.         return rep.GetLength(ev);
  441.     }
  442.     FW_SOM_CATCH
  443.     return 0;
  444. }
  445.  
  446.  
  447. //----------------------------------------------------------------------------------------
  448. // FW_OStorageUnitSink__SetLength
  449. //----------------------------------------------------------------------------------------
  450.  
  451. SOM_Scope void  SOMLINK FW_OStorageUnitSink__SetLength(FW_OStorageUnitSink *somSelf, Environment *ev,
  452.         long length)
  453. {
  454.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  455.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  456.  
  457.     FW_SOM_TRY
  458.     {
  459.         rep.SetLength(ev, length);
  460.     }
  461.     FW_SOM_CATCH
  462. }
  463.  
  464.  
  465. //----------------------------------------------------------------------------------------
  466. // FW_OStorageUnitSink__GetPosition
  467. //----------------------------------------------------------------------------------------
  468.  
  469. SOM_Scope long  SOMLINK FW_OStorageUnitSink__GetPosition(FW_OStorageUnitSink *somSelf, Environment *ev)
  470. {
  471.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  472.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  473.  
  474.     FW_SOM_TRY
  475.     {
  476.         return rep.GetPosition(ev);
  477.     }
  478.     FW_SOM_CATCH
  479.     return 0;
  480. }
  481.  
  482.  
  483. //----------------------------------------------------------------------------------------
  484. // FW_OStorageUnitSink__SetPosition
  485. //----------------------------------------------------------------------------------------
  486.  
  487. SOM_Scope void  SOMLINK FW_OStorageUnitSink__SetPosition(FW_OStorageUnitSink *somSelf, Environment *ev,
  488.         long position)
  489. {
  490.     FW_OStorageUnitSinkData *somThis = FW_OStorageUnitSinkGetData(somSelf);
  491.     FW_CPrivSUSinkRep& rep = *somThis->fRep;
  492.  
  493.     FW_SOM_TRY
  494.     {
  495.         rep.SetPosition(ev, position);
  496.     }
  497.     FW_SOM_CATCH
  498. }
  499.